package com.bsy.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

public class DianliangDao {
	public Map<String,Object>  query() {
		List<String> dianliangArr1 = new ArrayList<String>();
		List<Integer> dianliangArr2 = new ArrayList<Integer>();	
		Map<String, Object> map = new HashMap<String, Object>();
		Connection conn = null;
		Properties properties = new Properties();
		properties.setProperty("user", "root");
		properties.setProperty("password", "123456");
		properties.setProperty("useSSL", "false");
		properties.setProperty("autoReconnect", "true");

		try {
			Class.forName("com.mysql.jdbc.Driver");

		 conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bigdata_bsy?useUnicode=true&characterEncoding=utf-8",
					properties);
			PreparedStatement stmt = conn.prepareStatement("SELECT * FROM t_dianliang");
			ResultSet rs = stmt.executeQuery();
			
			while (rs.next()) {
				
				dianliangArr1.add(rs.getString("time"));
				dianliangArr2.add(rs.getInt("electricity"));
				
			}
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		map.put("time", dianliangArr1);
		map.put("electricity", dianliangArr2);
		return map;
	}

}
